using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using QLPMT_DTO;
namespace QLPMT_DAO
{
   public class HoaDonDAO
    {
       DataProvider provider;
       public HoaDonDAO()
       {
           provider = new DataProvider();
       }
       //Danh sach cac hoa don
       public List<HoaDon> GetALL()
       {
           provider.Connect();
           string sql = "select * from HoaDon";
           SqlDataReader reader = provider.ExecuteReader(sql);
           List<HoaDon> list = new List<HoaDon>();
           while (reader.Read())
           {
               string ma = reader.GetString(0);
               string maphieukham = reader.GetString(1);
               double tienthuoc = reader.GetDouble(2);
               double thanhtien = reader.GetDouble(3);
               HoaDon dto = new HoaDon(ma, maphieukham, tienthuoc, thanhtien);
               list.Add(dto);
           }
           provider.Disconnect();
           return list;
       }
       // Them 1 hoa don moi
       public void InsertHoaDon(HoaDon dto)
       {
           provider.Connect();
           string sql = "Insert into HoaDon(MaHoaDon,MaPhieuKham,TienThuoc,ThanhTien) values('"+dto.Mahoadon+"','"+dto.Maphieukham+"',"+dto.Tienthuoc+","+dto.Thanhtien+")";
           provider.ExecuteQuery(sql);
           provider.Disconnect();
       }
    }
}
